//
//  ViewController.m
//  DownloadManager
//
//  Created by 马滕亚 on 2020/4/14.
//  Copyright © 2020 M.Y.A. All rights reserved.
//

#import "ViewController.h"
#import "DownLoader.h"
#import "DownLoaderManager.h"

@interface ViewController ()

/** 下载管理器 */
@property (nonatomic, strong) DownLoader *downLoader;

/** url */
@property (nonatomic, strong) NSURL *url;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}

- (IBAction)startAction:(id)sender {
    NSURL *url = [NSURL URLWithString:@"https://dldir1.qq.com/qqfile/QQforMac/QQ_6.6.2.dmg"];
    self.url = url;
//    self.downLoader = [DownLoader new];
//    //    [downloader downloadWithUrl:url];
//
//    [self.downLoader downloadWithUrl:url progress:^(float progress) {
//
//        } completion:^(NSString * _Nonnull filePath) {
//            NSLog(@"---- %@",filePath);
//        } faied:^(NSString * _Nonnull errorMsg) {
//
//    }];
    
    
    [[DownLoaderManager shareDownLoaderManager] downloadWithUrl:url progress:^(float progress) {
        NSLog(@"----%f",progress);
    } completion:^(NSString * _Nonnull filePath) {
         NSLog(@"---- %@",filePath);
    } faied:^(NSString * _Nonnull errorMsg) {
         NSLog(@"---- %@",errorMsg);
    }];
}

- (IBAction)pauseAction:(id)sender {
//    [self.downLoader pause];
    
    [[DownLoaderManager shareDownLoaderManager] pauseWithUrl:self.url];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    NSURL *url = [NSURL URLWithString:@"http://127.0.0.1/text.vep"];
    DownLoader *downloader = [DownLoader new];
//    [downloader downloadWithUrl:url];
    
    [downloader downloadWithUrl:url progress:^(float progress) {
        
    } completion:^(NSString * _Nonnull filePath) {
        NSLog(@"---- %@",filePath);
    } faied:^(NSString * _Nonnull errorMsg) {
        
    }];
}


@end
